package com.google.code.whitetask;

import static com.google.code.whitetask.Result.FAILURE;
import static com.google.code.whitetask.Result.SUCCESS;

import java.util.ArrayList;
import java.util.List;

public class ChainTask implements Task {
  private List<Task> tasks = new ArrayList<Task>();
  
  public ChainTask(Task ... taskz) {
    for (Task each : taskz) {
      tasks.add(each);
    }
  }

  //TODO Task-Stack is needed?
  public Result execute(Context context) {
    for (Task each : tasks) {
      Result eachResult = each.execute(context);
      if (eachResult == FAILURE) {
        return FAILURE;
      }
    }
    
    return SUCCESS;
  }
}
